package 创建型模型.原型模式;

import java.util.Date;

public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        //浅复制,d修改则s1,s2的birthday属性都修改，因为此时只是浅复制，内部的属性对象索引还是同一个
        //但是name属性是字符串类型，不存在这在深浅复制，因为不是对象
        Date d=new Date(1212931L);
        String s="呵呵";
        Sheep s1=new Sheep(s,d);
        Sheep s2 = (Sheep) s1.clone();
//        System.out.println(s1.getBirthday());
        System.out.println(s1.getName());
        d.setTime(127418248L);
        s="测试";
//        System.out.println(s1.getBirthday());
//        System.out.println(s2.getBirthday());
        System.out.println(s1.getName());
        System.out.println(s2.getName());


        //深复制
        Date d1=new Date(1212931L);
        Sheep1 s11=new Sheep1("呵呵",d1);
        Sheep1 s21 = (Sheep1) s11.clone();
        System.out.println(s11.getBirthday());
        d1.setTime(127418248L);
        System.out.println(s11.getBirthday());
        System.out.println(s21.getBirthday());
    }
}
